package demo.miner.tools;

import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import jtech.Drawer;
import jtech.core.ImageUtils;

public class Sprite {

	private int pixelOffsetX;
	private int pixelOffsetY;
	private int pixelWidth;
	private int pixelHeight;

	private Image image;
	private String imagePath;
	
	public Sprite() {
		
	}
	
	public void loadImage() {
		image = new ImageIcon(imagePath).getImage();
		BufferedImage bi = ImageUtils.createCompatibleImage(image.getWidth(null), image.getHeight(null), Transparency.TRANSLUCENT);
		
	}
	
	public void drawImage(Drawer drawer, float x, float y, int direction, int frame) {
		int dx = Math.round(x + pixelOffsetX);
		int dy = Math.round(y + pixelOffsetY);
		int sx = (direction * pixelWidth);
		int sy = (frame * pixelHeight);
		drawer.draw(image, dx, dy, sx, sy, pixelWidth, pixelHeight);
	}
	
	public void drawDebug(Drawer drawer, float x, float y) {
		int dx = Math.round(x);
		int dy = Math.round(y);
		drawer.lineWidth1();
		drawer.gray().rect(dx+pixelOffsetX, dy+pixelOffsetY, pixelWidth, pixelHeight);
//		drawer.red().rect(dx, dy, baseWidth, baseHeight);
//		drawer.yellow().circle(dx+baseRadius, dy+baseRadius, baseRadius);
	}

	public int getPixelOffsetX() {
		return pixelOffsetX;
	}

	public void setPixelOffsetX(int pixelOffsetX) {
		this.pixelOffsetX = pixelOffsetX;
	}

	public int getPixelOffsetY() {
		return pixelOffsetY;
	}

	public void setPixelOffsetY(int pixelOffsetY) {
		this.pixelOffsetY = pixelOffsetY;
	}

	public int getPixelWidth() {
		return pixelWidth;
	}

	public void setPixelWidth(int pixelWidth) {
		this.pixelWidth = pixelWidth;
	}

	public int getPixelHeight() {
		return pixelHeight;
	}

	public void setPixelHeight(int pixelHeight) {
		this.pixelHeight = pixelHeight;
	}

	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}
	
}
